package group.sicher.core.data.annotations.tuple;


import group.sicher.core.data.annotations.UpdateTimestamp;
import group.sicher.core.utils.SicherDateUtils;
import org.hibernate.tuple.AnnotationValueGeneration;
import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.ValueGenerator;

/**
 * @author Donald
 * @description
 * @date 2019-05-08
 **/
public class UpdateTimestampGeneration implements AnnotationValueGeneration<UpdateTimestamp> {
    private ValueGenerator<?> generator;

    public UpdateTimestampGeneration() {
    }

    public void initialize(UpdateTimestamp annotation, Class<?> propertyType) {
        this.generator = (session, owner) -> SicherDateUtils.getCurrentTime();
    }

    public GenerationTiming getGenerationTiming() {
        return GenerationTiming.ALWAYS;
    }

    public ValueGenerator<?> getValueGenerator() {
        return this.generator;
    }

    public boolean referenceColumnInSql() {
        return false;
    }

    public String getDatabaseGeneratedReferencedColumnValue() {
        return null;
    }
}
